using System.Reflection;
using Runtime.Common.Utility;
using UnityEditor;
using UnityEditor.UI;
using UnityEngine;

namespace Runtime.Module.GameGraphic.Editor
{
    [InitializeOnLoad]
    public class ReplaceGraphicsEditor
    {
        static ReplaceGraphicsEditor()
        {
           // ReplaceFun();
        }

        class ReplaceGraphicsFun
        {
            public void OnInspectorGUI()
            {
                if (GUILayout.Button("dddd"))
                {
                }

                Debug.LogError("xxxxxxxxxxxxxxxxxxxxxxxx");
            }

            public Object Instantiate(Object original)
            {
                Debug.LogError("xxxxxxxxxxxxxxxxxxxxxxxx");
                return null;
            }
        }


        public static void ReplaceFun()
        {
            MethodInfo instance = typeof(Object).GetMethod("Instantiate",
                BindingFlags.Instance
                | BindingFlags.Public
                | BindingFlags.CreateInstance
                | BindingFlags.Static);
            ReplaceGraphicsFun fun1 = new ReplaceGraphicsFun();
            
            MethodInfo new_OnInspectorGUI1 = fun1.GetType().GetMethod("Instantiate",
                BindingFlags.Instance
                | BindingFlags.Public
                | BindingFlags.CreateInstance);
            MethodReplaceUtil.ReplaceMethod(instance, new_OnInspectorGUI1);
            return;
            MethodInfo onInspectorGUI = typeof(ImageEditor).GetMethod("OnInspectorGUI",
                BindingFlags.Instance
                | BindingFlags.Public
                | BindingFlags.CreateInstance);
            ReplaceGraphicsFun fun = new ReplaceGraphicsFun();

            MethodInfo new_OnInspectorGUI = fun.GetType().GetMethod("OnInspectorGUI",
                BindingFlags.Instance
                | BindingFlags.Public
                | BindingFlags.CreateInstance);
            MethodReplaceUtil.ReplaceMethod(onInspectorGUI, new_OnInspectorGUI);
            MethodInfo onInspectorGUI1 = typeof(GraphicEditor).GetMethod("OnInspectorGUI",
                BindingFlags.Instance
                | BindingFlags.Public
                | BindingFlags.CreateInstance);


            MethodReplaceUtil.ReplaceMethod(onInspectorGUI1, new_OnInspectorGUI);
        }
    }
}